﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Exp2
{
    public partial class Exp2 : Form
    {
        public Exp2()
        {
            InitializeComponent();
        }
        //智能电网信息工程专业学生类
        public class Student
        {
            protected string name;
            protected int age;
            protected double math;
            protected double english;
            public static int number;//静态数据成员，统计学生人数

            //构造函数
            public Student(string name, int age, double math, double english)
            {
                this.name = name;
                this.age = age;
                this.math = math;
                this.english = english;
                number++;

            }
            //返回学生信息
            public string GetMessage()
            {
                double average = (math + english) / 2;
                return string.Format("总人数{0}，智能电网学生{1}，{2}岁，平均成绩{3:F1}分\n", number, name, age, average);

            }
        }


        //选修VC#.NET程序设计课程学生类VCStudent
        public class VCStudent : Student
        {
            private double vcsharp;
            //构造函数
            public VCStudent(string name, int age, double math, double english, double vcsharp)
                : base(name, age, math, english)
            {
                this.vcsharp = vcsharp;
            }
            //返回学生信息，派生类定义新的GetMessage方法
            public new string GetMessage()
            {
                double average = (math + english + vcsharp) / 3;
                return string.Format("总人数{0}，VC#课学生{1}，{2}岁，平均成绩{3:F1}分\n", number, name, age, average);

            }

        }



        private void btnStudnet_Click(object sender, EventArgs e)
        {
            int age = Convert.ToInt32(txtAge.Text);
            double math = Convert.ToDouble(txtMath.Text);
            double english = Convert.ToDouble(txtEnglish.Text);
            Student stu = new Student(txtName.Text, age, math, english);
            lblShow.Text += stu.GetMessage();

        }

        private void btnSGStudent_Click(object sender, EventArgs e)
        {
            int age = Convert.ToInt32(txtAge.Text);
            double math = Convert.ToDouble(txtMath.Text);
            double english = Convert.ToDouble(txtEnglish.Text);
            double vcsharp = Convert.ToDouble(txtVCsharp.Text);
            VCStudent stu = new VCStudent(txtName.Text, age, math, english, vcsharp);
            lblShow.Text += stu.GetMessage();
        }


    }
}
